package mr.ali.video.web.controller;


import com.github.pagehelper.PageInfo;
import mr.ali.video.web.Exception.R;
import mr.ali.video.web.model.OpenId;
import mr.ali.video.web.service.IOpenIdService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Mr-ali
 * @since 2024-09-16
 */
@RestController
@RequestMapping("/web/open")
public class OpenIdController {
   @Resource
   private IOpenIdService openIdService;

   @GetMapping("/select")
   public R<PageInfo<OpenId>> getOpenId(Integer pageNum) {
      Integer pageSize = 12;
      return R.ok(openIdService.getOpenId(pageNum, pageSize));
   }
   @GetMapping("/selectById")
   public R<OpenId> getOpenIdById(Integer id) {
      OpenId openId = openIdService.getOpenIdByOpenId(id);
      if (openId == null) {
         return R.NOT_FOUND("该用户不存在");
      }
      return R.ok(openId);
   }
   /**
    * 非会员身份变成会员*/
   @PostMapping("/update")
   public R<Integer> updateOpenId(OpenId openId) {
      Integer rows = openIdService.updateOpenId(openId.getId(), openId.getStatus(), openId.getStatusCreate());
      if (rows == 0) {
         return R.INTERNAL_SERVER_ERROR("充值会员失败！");
      }
      return R.ok(rows);
   }
   /**
    * 会员身份变成非会员*/
   @PostMapping("/deleteStatus")
   public R<Integer> deleteOpenId(Integer id , Integer status) {
      Integer rows = openIdService.deleteStatus(id, status);
      if (rows == 0) {
         return R.INTERNAL_SERVER_ERROR("身份更新失败！");
      }
      return R.ok(rows);
   }
   /**
    * 会员总数量
    */
   @GetMapping("/count")
   public Integer count(Integer status) {
      Integer count =openIdService.getUserCount(status);
      return count;
   }
   /**
    * 会员总数量
    */
   @GetMapping("/countBy")
   public Integer countBy() {
      Integer count =openIdService.getUserCountBy();
      return count;
   }
}
